;--------------------------------------------------------
; File Created by SDCC : free open source ANSI-C Compiler
; Version 3.7.1 #0 (MSVC)
;--------------------------------------------------------
; NY8A port
;--------------------------------------------------------
	.file	"mcu\NY8\mcu_adc.c"
	list	p=NY8B062E,c=on
	#include "ny8b062e.inc"
	.debuginfo language C89
;--------------------------------------------------------
; external declarations
;--------------------------------------------------------
	extern	_sinf
	extern	_cosf
	extern	_tanf
	extern	_cotf
	extern	_asinf
	extern	_acosf
	extern	_atanf
	extern	_atan2f
	extern	_sinhf
	extern	_coshf
	extern	_tanhf
	extern	_expf
	extern	_logf
	extern	_log10f
	extern	_powf
	extern	_sqrtf
	extern	_fabsf
	extern	_frexpf
	extern	_ldexpf
	extern	_ceilf
	extern	_floorf
	extern	_modff
	extern	_isnan
	extern	_isinf
	extern	_multi_16b
	extern	_read_14bit_rom
	extern	_Mcu_Delayus
	extern	_Mcu_Delayms
	extern	_PORTAbits
	extern	_PORTBbits
	extern	_PCONbits
	extern	_BWUCONbits
	extern	_ABPLCONbits
	extern	_BPHCONbits
	extern	_INTEbits
	extern	_INTFbits
	extern	_ADMDbits
	extern	_ADRbits
	extern	_ADVREFHbits
	extern	_ADCRbits
	extern	_AWUCONbits
	extern	_PACONbits
	extern	_ADJMDbits
	extern	_INTEDGbits
	extern	_ANAENbits
	extern	_RFCbits
	extern	_INTE2bits
	extern	_INDF
	extern	_TMR0
	extern	_PCL
	extern	_STATUS
	extern	_FSR
	extern	_PORTA
	extern	_PORTB
	extern	_PCON
	extern	_BWUCON
	extern	_PCHBUF
	extern	_ABPLCON
	extern	_BPHCON
	extern	_INTE
	extern	_INTF
	extern	_ADMD
	extern	_ADR
	extern	_ADD
	extern	_ADVREFH
	extern	_ADCR
	extern	_AWUCON
	extern	_PACON
	extern	_ADJMD
	extern	_INTEDG
	extern	_TMRH
	extern	_ANAEN
	extern	_RFC
	extern	_TM3RH
	extern	_INTE2
	extern	_TMR1
	extern	_T1CR1
	extern	_T1CR2
	extern	_PWM1DUTY
	extern	_PS1CV
	extern	_BZ1CR
	extern	_IRCR
	extern	_TBHP
	extern	_TBHD
	extern	_TMR2
	extern	_T2CR1
	extern	_T2CR2
	extern	_PWM2DUTY
	extern	_PS2CV
	extern	_BZ2CR
	extern	_OSCCR
	extern	_TMR3
	extern	_T3CR1
	extern	_T3CR2
	extern	_PWM3DUTY
	extern	_PS3CV
	extern	_BZ3CR
	extern	_P4CR1
	extern	_PWM4DUTY
	extern	_IOSTA
	extern	_IOSTB
	extern	_APHCON
	extern	_PS0CV
	extern	_BODCON
	extern	_CMPCR
	extern	_PCON1
	extern	_T0MD

	extern PSAVE
	extern SSAVE
	extern WSAVE
	extern STK04
	extern STK03
	extern STK02
	extern STK01
	extern STK00
;--------------------------------------------------------
; global declarations
;--------------------------------------------------------
	extern	_Adc_SetVref
	extern	_Adc_Start
	extern	_Adc_GetOnce
	extern	__Adc_mDiscard

;--------------------------------------------------------
; global definitions
;--------------------------------------------------------
;--------------------------------------------------------
; absolute symbol definitions
;--------------------------------------------------------
;--------------------------------------------------------
; compiler-defined variables
;--------------------------------------------------------
.segment "uninit"
r0x1004:
	.res	1
.segment "uninit"
r0x1002:
	.res	1
.segment "uninit"
r0x1001:
	.res	1
;--------------------------------------------------------
; initialized data
;--------------------------------------------------------

.segment "idata"
__Adc_mDiscard:
	dw	0x00
	.debuginfo gvariable name=__Adc_mDiscard,1byte,array=0,entsize=1,ext=1,enc=unsigned

;--------------------------------------------------------
; overlayable items in internal ram 
;--------------------------------------------------------
;	udata_ovr
;--------------------------------------------------------
; code
;--------------------------------------------------------
;***
;  pBlock Stats: dbName = C
;***
;has an exit
;1 compiler assigned register :
;   r0x1001
;; Starting pCode block
.segment "code"; module=mcu_adc, function=_Adc_SetVref
	.debuginfo subprogram _Adc_SetVref
;local variable name mapping:
	.debuginfo variable _vref=r0x1001,enc=unsigned
_Adc_SetVref:
; 2 exit points
	.line	67, "mcu\NY8\mcu_adc.c"; 	void Adc_SetVref(adc_vref_t vref)
	BANKSEL	r0x1001
	MOVAR	r0x1001
	.line	69, "mcu\NY8\mcu_adc.c"; 	if(Adc_GetVref() != vref)
	XORAR	_ADVREFH,W
	BTRSC	STATUS,2
	MGOTO	_00001_DS_
	.line	71, "mcu\NY8\mcu_adc.c"; 	_Adc_mDiscard = 0;  // 重新开始记录丢弃笔数
	BANKSEL	__Adc_mDiscard
	CLRR	__Adc_mDiscard
_00001_DS_:
	.line	73, "mcu\NY8\mcu_adc.c"; 	ADVREFH = vref;
	BANKSEL	r0x1001
	MOVR	r0x1001,W
	MOVAR	_ADVREFH
	.line	74, "mcu\NY8\mcu_adc.c"; 	}
	RETURN	
; exit point of _Adc_SetVref

;***
;  pBlock Stats: dbName = C
;***
;has an exit
;2 compiler assigned registers:
;   r0x1002
;   r0x1003
;; Starting pCode block
.segment "code"; module=mcu_adc, function=_Adc_Start
	.debuginfo subprogram _Adc_Start
;local variable name mapping:
	.debuginfo variable _ch=r0x1002,enc=unsigned
_Adc_Start:
; 2 exit points
	.line	54, "mcu\NY8\mcu_adc.c"; 	void Adc_Start(u8 ch)
	BANKSEL	r0x1002
	MOVAR	r0x1002
	.line	56, "mcu\NY8\mcu_adc.c"; 	if(Adc_GetCH() != ch)
	MOVIA	0x0f
	ANDAR	_ADMD,W
;;1	MOVAR	r0x1003
	XORAR	r0x1002,W
	BTRSC	STATUS,2
	MGOTO	_00117_DS_
	.line	60, "mcu\NY8\mcu_adc.c"; 	ADMD = 0X90|ch; 
	MOVIA	0x90
	IORAR	r0x1002,W
	MOVAR	_ADMD
	.line	61, "mcu\NY8\mcu_adc.c"; 	_Adc_mDiscard = 0;  // 重新开始记录丢弃笔数
	BANKSEL	__Adc_mDiscard
	CLRR	__Adc_mDiscard
_00117_DS_:
	.line	63, "mcu\NY8\mcu_adc.c"; 	_Adc_mRunning = true;
	BSR	_PCONbits,0
	.line	64, "mcu\NY8\mcu_adc.c"; 	START = 1;
	BSR	_ADMD,6
	.line	65, "mcu\NY8\mcu_adc.c"; 	}
	RETURN	
; exit point of _Adc_Start

;***
;  pBlock Stats: dbName = C
;***
;has an exit
;functions called:
;   _Adc_Start
;   _Adc_Start
;1 compiler assigned register :
;   r0x1004
;; Starting pCode block
.segment "code"; module=mcu_adc, function=_Adc_GetOnce
	.debuginfo subprogram _Adc_GetOnce
;local variable name mapping:
	.debuginfo variable _ch=r0x1004,enc=unsigned
_Adc_GetOnce:
; 2 exit points
	.line	18, "mcu\NY8\mcu_adc.c"; 	u8 Adc_GetOnce(u8 ch)
	BANKSEL	r0x1004
	MOVAR	r0x1004
	.line	20, "mcu\NY8\mcu_adc.c"; 	ADIE = 0;
	BANKSEL	_ADR
	BCR	_ADR,6
	.line	21, "mcu\NY8\mcu_adc.c"; 	Adc_Start(ch);
	BANKSEL	r0x1004
	MOVR	r0x1004,W
	MCALL	_Adc_Start
;;unsigned compare: left < lit (0x8=8), size=1
_00108_DS_:
	.line	22, "mcu\NY8\mcu_adc.c"; 	while(_Adc_mDiscard < ADC_DISCARD_NUM)
	MOVIA	0x08
	BANKSEL	__Adc_mDiscard
	SUBAR	__Adc_mDiscard,W
	BTRSC	STATUS,0
	MGOTO	_00111_DS_
_00105_DS_:
	.line	24, "mcu\NY8\mcu_adc.c"; 	while(EOC == 0);
	BTRSS	_ADMD,5
	MGOTO	_00105_DS_
	.line	25, "mcu\NY8\mcu_adc.c"; 	_Adc_mDiscard++;
	BANKSEL	__Adc_mDiscard
	INCR	__Adc_mDiscard,F
	.line	26, "mcu\NY8\mcu_adc.c"; 	START = 1;	/* 继续转换 */
	BSR	_ADMD,6
	MGOTO	_00108_DS_
_00111_DS_:
	.line	28, "mcu\NY8\mcu_adc.c"; 	while(EOC == 0);
	BTRSS	_ADMD,5
	MGOTO	_00111_DS_
	.line	29, "mcu\NY8\mcu_adc.c"; 	ADIF = 0;
	BANKSEL	_ADR
	BCR	_ADR,7
	.line	30, "mcu\NY8\mcu_adc.c"; 	ADIE = 1;
	BSR	_ADR,6
	.line	31, "mcu\NY8\mcu_adc.c"; 	_Adc_mRunning = false;
	BCR	_PCONbits,0
	.line	32, "mcu\NY8\mcu_adc.c"; 	return ADD;
	MOVR	_ADD,W
	.line	33, "mcu\NY8\mcu_adc.c"; 	}
	RETURN	
; exit point of _Adc_GetOnce


;	code size estimation:
;	   41+   11 =    52 instructions (  126 byte)

	end
